<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE Unsafe #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE NoImplicitPrelude
           , BangPatterns
           , RankNTypes
           , MagicHash
           , ScopedTypeVariables
           , UnboxedTuples
  #-}</span><span>
</span><span id="line-9"></span><span class="hs-pragma">{-# OPTIONS_GHC -funbox-strict-fields #-}</span><span>
</span><span id="line-10"></span><span class="hs-pragma">{-# OPTIONS_HADDOCK not-home #-}</span><span>
</span><span id="line-11"></span><span>
</span><span id="line-12"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-13"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-14"></span><span class="hs-comment">-- Module      :  GHC.IO</span><span>
</span><span id="line-15"></span><span class="hs-comment">-- Copyright   :  (c) The University of Glasgow 1994-2002</span><span>
</span><span id="line-16"></span><span class="hs-comment">-- License     :  see libraries/base/LICENSE</span><span>
</span><span id="line-17"></span><span class="hs-comment">--</span><span>
</span><span id="line-18"></span><span class="hs-comment">-- Maintainer  :  cvs-ghc@haskell.org</span><span>
</span><span id="line-19"></span><span class="hs-comment">-- Stability   :  internal</span><span>
</span><span id="line-20"></span><span class="hs-comment">-- Portability :  non-portable (GHC Extensions)</span><span>
</span><span id="line-21"></span><span class="hs-comment">--</span><span>
</span><span id="line-22"></span><span class="hs-comment">-- Definitions for the 'IO' monad and its friends.</span><span>
</span><span id="line-23"></span><span class="hs-comment">--</span><span>
</span><span id="line-24"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-25"></span><span>
</span><span id="line-26"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.IO</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-27"></span><span>        </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier">IO</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Base.html#unIO"><span class="hs-identifier">unIO</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.html#liftIO"><span class="hs-identifier">liftIO</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.html#mplusIO"><span class="hs-identifier">mplusIO</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-28"></span><span>        </span><span class="annot"><a href="GHC.IO.Unsafe.html#unsafePerformIO"><span class="hs-identifier">unsafePerformIO</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Unsafe.html#unsafeInterleaveIO"><span class="hs-identifier">unsafeInterleaveIO</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-29"></span><span>        </span><span class="annot"><a href="GHC.IO.Unsafe.html#unsafeDupablePerformIO"><span class="hs-identifier">unsafeDupablePerformIO</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Unsafe.html#unsafeDupableInterleaveIO"><span class="hs-identifier">unsafeDupableInterleaveIO</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-30"></span><span>        </span><span class="annot"><a href="GHC.IO.Unsafe.html#noDuplicate"><span class="hs-identifier">noDuplicate</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-31"></span><span>
</span><span id="line-32"></span><span>        </span><span class="hs-comment">-- To and from ST</span><span>
</span><span id="line-33"></span><span>        </span><span class="annot"><a href="GHC.IO.html#stToIO"><span class="hs-identifier">stToIO</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.html#ioToST"><span class="hs-identifier">ioToST</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.html#unsafeIOToST"><span class="hs-identifier">unsafeIOToST</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.html#unsafeSTToIO"><span class="hs-identifier">unsafeSTToIO</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-34"></span><span>
</span><span id="line-35"></span><span>        </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier">FilePath</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-36"></span><span>
</span><span id="line-37"></span><span>        </span><span class="annot"><a href="GHC.IO.html#catch"><span class="hs-identifier">catch</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.html#catchException"><span class="hs-identifier">catchException</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.html#catchAny"><span class="hs-identifier">catchAny</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.html#throwIO"><span class="hs-identifier">throwIO</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-38"></span><span>        </span><span class="annot"><a href="GHC.IO.html#mask"><span class="hs-identifier">mask</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.html#mask_"><span class="hs-identifier">mask_</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.html#uninterruptibleMask"><span class="hs-identifier">uninterruptibleMask</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.html#uninterruptibleMask_"><span class="hs-identifier">uninterruptibleMask_</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-39"></span><span>        </span><span class="annot"><a href="GHC.IO.html#MaskingState"><span class="hs-identifier">MaskingState</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.html#getMaskingState"><span class="hs-identifier">getMaskingState</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-40"></span><span>        </span><span class="annot"><a href="GHC.IO.html#unsafeUnmask"><span class="hs-identifier">unsafeUnmask</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.html#interruptible"><span class="hs-identifier">interruptible</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-41"></span><span>        </span><span class="annot"><a href="GHC.IO.html#onException"><span class="hs-identifier">onException</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.html#bracket"><span class="hs-identifier">bracket</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.html#finally"><span class="hs-identifier">finally</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.html#evaluate"><span class="hs-identifier">evaluate</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-42"></span><span>        </span><span class="annot"><a href="GHC.IO.html#mkUserError"><span class="hs-identifier">mkUserError</span></a></span><span>
</span><span id="line-43"></span><span>    </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-44"></span><span>
</span><span id="line-45"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Base.html"><span class="hs-identifier">GHC.Base</span></a></span><span>
</span><span id="line-46"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.ST.html"><span class="hs-identifier">GHC.ST</span></a></span><span>
</span><span id="line-47"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Exception.html"><span class="hs-identifier">GHC.Exception</span></a></span><span>
</span><span id="line-48"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Show.html"><span class="hs-identifier">GHC.Show</span></a></span><span>
</span><span id="line-49"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Unsafe.html"><span class="hs-identifier">GHC.IO.Unsafe</span></a></span><span>
</span><span id="line-50"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Unsafe.Coerce.html"><span class="hs-identifier">Unsafe.Coerce</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="Unsafe.Coerce.html#unsafeCoerce"><span class="hs-identifier">unsafeCoerce</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-51"></span><span>
</span><span id="line-52"></span><span class="hs-keyword">import</span><span> </span><span class="hs-pragma">{-# SOURCE</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="annot"><a href="GHC.IO.Exception.html"><span class="hs-identifier">GHC.IO.Exception</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.IO.Exception.html#userError"><span class="hs-identifier">userError</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Exception.html#IOError"><span class="hs-identifier">IOError</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-53"></span><span>
</span><span id="line-54"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-55"></span><span class="hs-comment">-- The IO Monad</span><span>
</span><span id="line-56"></span><span>
</span><span id="line-57"></span><span class="hs-comment">{-
The IO Monad is just an instance of the ST monad, where the state thread
is the real world.  We use the exception mechanism (in GHC.Exception) to
implement IO exceptions.

NOTE: The IO representation is deeply wired in to various parts of the
system.  The following list may or may not be exhaustive:

Compiler  - types of various primitives in GHC.Builtin.PrimOps

RTS       - forceIO (StgStartup.cmm)
          - catchzh_fast, (un)?blockAsyncExceptionszh_fast, raisezh_fast
            (Exception.cmm)
          - raiseAsync (RaiseAsync.c)

Prelude   - GHC.IO.hs, and several other places including
            GHC.Exception.hs.

Libraries - parts of hslibs/lang.

--SDM
-}</span><span>
</span><span id="line-79"></span><span>
</span><span id="line-80"></span><span id="local-6989586621679531433"><span class="annot"><a href="GHC.IO.html#liftIO"><span class="hs-identifier hs-type">liftIO</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531433"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#State%23"><span class="hs-identifier hs-type">State#</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#RealWorld"><span class="hs-identifier hs-type">RealWorld</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.ST.html#STret"><span class="hs-identifier hs-type">STret</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#RealWorld"><span class="hs-identifier hs-type">RealWorld</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531433"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-81"></span><span id="liftIO"><span class="annot"><span class="annottext">liftIO :: forall a. IO a -&gt; State# RealWorld -&gt; STret RealWorld a
</span><a href="GHC.IO.html#liftIO"><span class="hs-identifier hs-var hs-var">liftIO</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span id="local-6989586621679531316"><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679531316"><span class="hs-identifier hs-var">m</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679531315"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679531315"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679531316"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679531315"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">(#</span><span> </span><span id="local-6989586621679531314"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679531314"><span class="hs-identifier hs-var">s'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679531313"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679531313"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-special">#)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">State# RealWorld -&gt; a -&gt; STret RealWorld a
forall s a. State# s -&gt; a -&gt; STret s a
</span><a href="GHC.ST.html#STret"><span class="hs-identifier hs-var">STret</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679531314"><span class="hs-identifier hs-var">s'</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679531313"><span class="hs-identifier hs-var">r</span></a></span><span>
</span><span id="line-82"></span><span>
</span><span id="line-83"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-84"></span><span class="hs-comment">-- Coercions between IO and ST</span><span>
</span><span id="line-85"></span><span>
</span><span id="line-86"></span><span class="hs-comment">-- | Embed a strict state thread in an 'IO'</span><span>
</span><span id="line-87"></span><span class="hs-comment">-- action.  The 'RealWorld' parameter indicates that the internal state</span><span>
</span><span id="line-88"></span><span class="hs-comment">-- used by the 'ST' computation is a special one supplied by the 'IO'</span><span>
</span><span id="line-89"></span><span class="hs-comment">-- monad, and thus distinct from those used by invocations of 'runST'.</span><span>
</span><span id="line-90"></span><span id="local-6989586621679531428"><span class="annot"><a href="GHC.IO.html#stToIO"><span class="hs-identifier hs-type">stToIO</span></a></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.ST.html#ST"><span class="hs-identifier hs-type">ST</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#RealWorld"><span class="hs-identifier hs-type">RealWorld</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531428"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531428"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-91"></span><span id="stToIO"><span class="annot"><span class="annottext">stToIO :: forall a. ST RealWorld a -&gt; IO a
</span><a href="GHC.IO.html#stToIO"><span class="hs-identifier hs-var hs-var">stToIO</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.ST.html#ST"><span class="hs-identifier hs-type">ST</span></a></span><span> </span><span id="local-6989586621679531310"><span class="annot"><span class="annottext">STRep RealWorld a
</span><a href="#local-6989586621679531310"><span class="hs-identifier hs-var">m</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">STRep RealWorld a -&gt; IO a
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">STRep RealWorld a
</span><a href="#local-6989586621679531310"><span class="hs-identifier hs-var">m</span></a></span><span>
</span><span id="line-92"></span><span>
</span><span id="line-93"></span><span class="hs-comment">-- | Convert an 'IO' action into an 'ST' action. The type of the result</span><span>
</span><span id="line-94"></span><span class="hs-comment">-- is constrained to use a 'RealWorld' state thread, and therefore the</span><span>
</span><span id="line-95"></span><span class="hs-comment">-- result cannot be passed to 'runST'.</span><span>
</span><span id="line-96"></span><span id="local-6989586621679531423"><span class="annot"><a href="GHC.IO.html#ioToST"><span class="hs-identifier hs-type">ioToST</span></a></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531423"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.ST.html#ST"><span class="hs-identifier hs-type">ST</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Prim.html#RealWorld"><span class="hs-identifier hs-type">RealWorld</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531423"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-97"></span><span id="ioToST"><span class="annot"><span class="annottext">ioToST :: forall a. IO a -&gt; ST RealWorld a
</span><a href="GHC.IO.html#ioToST"><span class="hs-identifier hs-var hs-var">ioToST</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span id="local-6989586621679531309"><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679531309"><span class="hs-identifier hs-var">m</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; ST RealWorld a
forall s a. STRep s a -&gt; ST s a
</span><a href="GHC.ST.html#ST"><span class="hs-identifier hs-var">ST</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679531309"><span class="hs-identifier hs-var">m</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-98"></span><span>
</span><span id="line-99"></span><span class="hs-comment">-- | Convert an 'IO' action to an 'ST' action.</span><span>
</span><span id="line-100"></span><span class="hs-comment">-- This relies on 'IO' and 'ST' having the same representation modulo the</span><span>
</span><span id="line-101"></span><span class="hs-comment">-- constraint on the state thread type parameter.</span><span>
</span><span id="line-102"></span><span id="local-6989586621679531418"><span id="local-6989586621679531419"><span class="annot"><a href="GHC.IO.html#unsafeIOToST"><span class="hs-identifier hs-type">unsafeIOToST</span></a></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531419"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.ST.html#ST"><span class="hs-identifier hs-type">ST</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531418"><span class="hs-identifier hs-type">s</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531419"><span class="hs-identifier hs-type">a</span></a></span></span></span><span>
</span><span id="line-103"></span><span id="unsafeIOToST"><span class="annot"><span class="annottext">unsafeIOToST :: forall a s. IO a -&gt; ST s a
</span><a href="GHC.IO.html#unsafeIOToST"><span class="hs-identifier hs-var hs-var">unsafeIOToST</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span id="local-6989586621679531308"><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679531308"><span class="hs-identifier hs-var">io</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">STRep s a -&gt; ST s a
forall s a. STRep s a -&gt; ST s a
</span><a href="GHC.ST.html#ST"><span class="hs-identifier hs-var">ST</span></a></span><span> </span><span class="annot"><span class="annottext">(STRep s a -&gt; ST s a) -&gt; STRep s a -&gt; ST s a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679531307"><span class="annot"><span class="annottext">State# s
</span><a href="#local-6989586621679531307"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; STRep s a
forall a b. a -&gt; b
</span><a href="Unsafe.Coerce.html#unsafeCoerce"><span class="hs-identifier hs-var">unsafeCoerce</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679531308"><span class="hs-identifier hs-var">io</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">State# s
</span><a href="#local-6989586621679531307"><span class="hs-identifier hs-var">s</span></a></span><span>
</span><span id="line-104"></span><span>
</span><span id="line-105"></span><span class="hs-comment">-- | Convert an 'ST' action to an 'IO' action.</span><span>
</span><span id="line-106"></span><span class="hs-comment">-- This relies on 'IO' and 'ST' having the same representation modulo the</span><span>
</span><span id="line-107"></span><span class="hs-comment">-- constraint on the state thread type parameter.</span><span>
</span><span id="line-108"></span><span class="hs-comment">--</span><span>
</span><span id="line-109"></span><span class="hs-comment">-- For an example demonstrating why this is unsafe, see</span><span>
</span><span id="line-110"></span><span class="hs-comment">-- https://mail.haskell.org/pipermail/haskell-cafe/2009-April/060719.html</span><span>
</span><span id="line-111"></span><span id="local-6989586621679531409"><span id="local-6989586621679531410"><span class="annot"><a href="GHC.IO.html#unsafeSTToIO"><span class="hs-identifier hs-type">unsafeSTToIO</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.ST.html#ST"><span class="hs-identifier hs-type">ST</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531410"><span class="hs-identifier hs-type">s</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531409"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531409"><span class="hs-identifier hs-type">a</span></a></span></span></span><span>
</span><span id="line-112"></span><span id="unsafeSTToIO"><span class="annot"><span class="annottext">unsafeSTToIO :: forall s a. ST s a -&gt; IO a
</span><a href="GHC.IO.html#unsafeSTToIO"><span class="hs-identifier hs-var hs-var">unsafeSTToIO</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.ST.html#ST"><span class="hs-identifier hs-type">ST</span></a></span><span> </span><span id="local-6989586621679531306"><span class="annot"><span class="annottext">STRep s a
</span><a href="#local-6989586621679531306"><span class="hs-identifier hs-var">m</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">STRep s a -&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
forall a b. a -&gt; b
</span><a href="Unsafe.Coerce.html#unsafeCoerce"><span class="hs-identifier hs-var">unsafeCoerce</span></a></span><span> </span><span class="annot"><span class="annottext">STRep s a
</span><a href="#local-6989586621679531306"><span class="hs-identifier hs-var">m</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-113"></span><span>
</span><span id="line-114"></span><span class="hs-comment">-- -----------------------------------------------------------------------------</span><span>
</span><span id="line-115"></span><span class="hs-comment">-- | File and directory names are values of type 'String', whose precise</span><span>
</span><span id="line-116"></span><span class="hs-comment">-- meaning is operating system dependent. Files can be opened, yielding a</span><span>
</span><span id="line-117"></span><span class="hs-comment">-- handle which can then be used to operate on the contents of that file.</span><span>
</span><span id="line-118"></span><span>
</span><span id="line-119"></span><span class="hs-keyword">type</span><span> </span><span id="FilePath"><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-var">FilePath</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-120"></span><span>
</span><span id="line-121"></span><span class="hs-comment">-- -----------------------------------------------------------------------------</span><span>
</span><span id="line-122"></span><span class="hs-comment">-- Primitive catch and throwIO</span><span>
</span><span id="line-123"></span><span>
</span><span id="line-124"></span><span class="hs-comment">{-
catchException/catch used to handle the passing around of the state to the
action and the handler.  This turned out to be a bad idea - it meant
that we had to wrap both arguments in thunks so they could be entered
as normal (remember IO returns an unboxed pair...).

Now catch# has type

    catch# :: IO a -&gt; (b -&gt; IO a) -&gt; IO a

(well almost; the compiler doesn't know about the IO newtype so we
have to work around that in the definition of catch below).
-}</span><span>
</span><span id="line-137"></span><span>
</span><span id="line-138"></span><span class="hs-comment">-- | Catch an exception in the 'IO' monad.</span><span>
</span><span id="line-139"></span><span class="hs-comment">--</span><span>
</span><span id="line-140"></span><span class="hs-comment">-- Note that this function is /strict/ in the action. That is,</span><span>
</span><span id="line-141"></span><span class="hs-comment">-- @catchException undefined b == _|_@. See #exceptions_and_strictness#</span><span>
</span><span id="line-142"></span><span class="hs-comment">-- for details.</span><span>
</span><span id="line-143"></span><span id="local-6989586621679531405"><span id="local-6989586621679531406"><span class="annot"><a href="GHC.IO.html#catchException"><span class="hs-identifier hs-type">catchException</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Exception.Type.html#Exception"><span class="hs-identifier hs-type">Exception</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531406"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531405"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679531406"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531405"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531405"><span class="hs-identifier hs-type">a</span></a></span></span></span><span>
</span><span id="line-144"></span><span id="catchException"><span class="annot"><span class="annottext">catchException :: forall e a. Exception e =&gt; IO a -&gt; (e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.html#catchException"><span class="hs-identifier hs-var hs-var">catchException</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679531303"><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679531303"><span class="hs-identifier hs-var">io</span></a></span></span><span> </span><span id="local-6989586621679531302"><span class="annot"><span class="annottext">e -&gt; IO a
</span><a href="#local-6989586621679531302"><span class="hs-identifier hs-var">handler</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO a -&gt; (e -&gt; IO a) -&gt; IO a
forall e a. Exception e =&gt; IO a -&gt; (e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.html#catch"><span class="hs-identifier hs-var">catch</span></a></span><span> </span><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679531303"><span class="hs-identifier hs-var">io</span></a></span><span> </span><span class="annot"><span class="annottext">e -&gt; IO a
</span><a href="#local-6989586621679531302"><span class="hs-identifier hs-var">handler</span></a></span><span>
</span><span id="line-145"></span><span>
</span><span id="line-146"></span><span class="hs-comment">-- | This is the simplest of the exception-catching functions.  It</span><span>
</span><span id="line-147"></span><span class="hs-comment">-- takes a single argument, runs it, and if an exception is raised</span><span>
</span><span id="line-148"></span><span class="hs-comment">-- the \&quot;handler\&quot; is executed, with the value of the exception passed as an</span><span>
</span><span id="line-149"></span><span class="hs-comment">-- argument.  Otherwise, the result is returned as normal.  For example:</span><span>
</span><span id="line-150"></span><span class="hs-comment">--</span><span>
</span><span id="line-151"></span><span class="hs-comment">-- &gt;   catch (readFile f)</span><span>
</span><span id="line-152"></span><span class="hs-comment">-- &gt;         (\e -&gt; do let err = show (e :: IOException)</span><span>
</span><span id="line-153"></span><span class="hs-comment">-- &gt;                   hPutStr stderr (&quot;Warning: Couldn't open &quot; ++ f ++ &quot;: &quot; ++ err)</span><span>
</span><span id="line-154"></span><span class="hs-comment">-- &gt;                   return &quot;&quot;)</span><span>
</span><span id="line-155"></span><span class="hs-comment">--</span><span>
</span><span id="line-156"></span><span class="hs-comment">-- Note that we have to give a type signature to @e@, or the program</span><span>
</span><span id="line-157"></span><span class="hs-comment">-- will not typecheck as the type is ambiguous. While it is possible</span><span>
</span><span id="line-158"></span><span class="hs-comment">-- to catch exceptions of any type, see the section \&quot;Catching all</span><span>
</span><span id="line-159"></span><span class="hs-comment">-- exceptions\&quot; (in &quot;Control.Exception&quot;) for an explanation of the problems with doing so.</span><span>
</span><span id="line-160"></span><span class="hs-comment">--</span><span>
</span><span id="line-161"></span><span class="hs-comment">-- For catching exceptions in pure (non-'IO') expressions, see the</span><span>
</span><span id="line-162"></span><span class="hs-comment">-- function 'evaluate'.</span><span>
</span><span id="line-163"></span><span class="hs-comment">--</span><span>
</span><span id="line-164"></span><span class="hs-comment">-- Note that due to Haskell\'s unspecified evaluation order, an</span><span>
</span><span id="line-165"></span><span class="hs-comment">-- expression may throw one of several possible exceptions: consider</span><span>
</span><span id="line-166"></span><span class="hs-comment">-- the expression @(error \&quot;urk\&quot;) + (1 \`div\` 0)@.  Does</span><span>
</span><span id="line-167"></span><span class="hs-comment">-- the expression throw</span><span>
</span><span id="line-168"></span><span class="hs-comment">-- @ErrorCall \&quot;urk\&quot;@, or @DivideByZero@?</span><span>
</span><span id="line-169"></span><span class="hs-comment">--</span><span>
</span><span id="line-170"></span><span class="hs-comment">-- The answer is \&quot;it might throw either\&quot;; the choice is</span><span>
</span><span id="line-171"></span><span class="hs-comment">-- non-deterministic. If you are catching any type of exception then you</span><span>
</span><span id="line-172"></span><span class="hs-comment">-- might catch either. If you are calling @catch@ with type</span><span>
</span><span id="line-173"></span><span class="hs-comment">-- @IO Int -&gt; (ArithException -&gt; IO Int) -&gt; IO Int@ then the handler may</span><span>
</span><span id="line-174"></span><span class="hs-comment">-- get run with @DivideByZero@ as an argument, or an @ErrorCall \&quot;urk\&quot;@</span><span>
</span><span id="line-175"></span><span class="hs-comment">-- exception may be propagated further up. If you call it again, you</span><span>
</span><span id="line-176"></span><span class="hs-comment">-- might get a the opposite behaviour. This is ok, because 'catch' is an</span><span>
</span><span id="line-177"></span><span class="hs-comment">-- 'IO' computation.</span><span>
</span><span id="line-178"></span><span class="hs-comment">--</span><span>
</span><span id="line-179"></span><span id="local-6989586621679531300"><span id="local-6989586621679531301"><span class="annot"><a href="GHC.IO.html#catch"><span class="hs-identifier hs-type">catch</span></a></span><span>   </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Exception.Type.html#Exception"><span class="hs-identifier hs-type">Exception</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531301"><span class="hs-identifier hs-type">e</span></a></span><span>
</span><span id="line-180"></span><span>        </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531300"><span class="hs-identifier hs-type">a</span></a></span><span>         </span><span class="hs-comment">-- ^ The computation to run</span><span>
</span><span id="line-181"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679531301"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531300"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>  </span><span class="hs-comment">-- ^ Handler to invoke if an exception is raised</span><span>
</span><span id="line-182"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531300"><span class="hs-identifier hs-type">a</span></a></span></span></span><span>
</span><span id="line-183"></span><span class="hs-comment">-- See #exceptions_and_strictness#.</span><span>
</span><span id="line-184"></span><span id="catch"><span class="annot"><span class="annottext">catch :: forall e a. Exception e =&gt; IO a -&gt; (e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.html#catch"><span class="hs-identifier hs-var hs-var">catch</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span id="local-6989586621679531298"><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679531298"><span class="hs-identifier hs-var">io</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679531297"><span class="annot"><span class="annottext">e -&gt; IO a
</span><a href="#local-6989586621679531297"><span class="hs-identifier hs-var">handler</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a)
-&gt; (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, a #))
-&gt; (SomeException -&gt; State# RealWorld -&gt; (# State# RealWorld, a #))
-&gt; State# RealWorld
-&gt; (# State# RealWorld, a #)
forall a b.
(State# RealWorld -&gt; (# State# RealWorld, a #))
-&gt; (b -&gt; State# RealWorld -&gt; (# State# RealWorld, a #))
-&gt; State# RealWorld
-&gt; (# State# RealWorld, a #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#catch%23"><span class="hs-identifier hs-var">catch#</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679531298"><span class="hs-identifier hs-var">io</span></a></span><span> </span><span class="annot"><span class="annottext">SomeException -&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679531296"><span class="hs-identifier hs-var">handler'</span></a></span><span>
</span><span id="line-185"></span><span>    </span><span class="hs-keyword">where</span><span> </span><span id="local-6989586621679531296"><span class="annot"><span class="annottext">handler' :: SomeException -&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679531296"><span class="hs-identifier hs-var hs-var">handler'</span></a></span></span><span> </span><span id="local-6989586621679531294"><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679531294"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">SomeException -&gt; Maybe e
forall e. Exception e =&gt; SomeException -&gt; Maybe e
</span><a href="GHC.Exception.Type.html#fromException"><span class="hs-identifier hs-var">fromException</span></a></span><span> </span><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679531294"><span class="hs-identifier hs-var">e</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-186"></span><span>                       </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679531292"><span class="annot"><span class="annottext">e
</span><a href="#local-6989586621679531292"><span class="hs-identifier hs-var">e'</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IO a -&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
forall a. IO a -&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="GHC.Base.html#unIO"><span class="hs-identifier hs-var">unIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">e -&gt; IO a
</span><a href="#local-6989586621679531297"><span class="hs-identifier hs-var">handler</span></a></span><span> </span><span class="annot"><span class="annottext">e
</span><a href="#local-6989586621679531292"><span class="hs-identifier hs-var">e'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-187"></span><span>                       </span><span class="annot"><span class="annottext">Maybe e
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">SomeException -&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
forall a b. a -&gt; State# RealWorld -&gt; (# State# RealWorld, b #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#raiseIO%23"><span class="hs-identifier hs-var">raiseIO#</span></a></span><span> </span><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679531294"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-188"></span><span>
</span><span id="line-189"></span><span>
</span><span id="line-190"></span><span class="hs-comment">-- | Catch any 'Exception' type in the 'IO' monad.</span><span>
</span><span id="line-191"></span><span class="hs-comment">--</span><span>
</span><span id="line-192"></span><span class="hs-comment">-- Note that this function is /strict/ in the action. That is,</span><span>
</span><span id="line-193"></span><span class="hs-comment">-- @catchAny undefined b == _|_@. See #exceptions_and_strictness# for</span><span>
</span><span id="line-194"></span><span class="hs-comment">-- details.</span><span>
</span><span id="line-195"></span><span id="local-6989586621679531395"><span class="annot"><a href="GHC.IO.html#catchAny"><span class="hs-identifier hs-type">catchAny</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531395"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679531394"><span class="annot"><a href="#local-6989586621679531394"><span class="hs-identifier hs-type">e</span></a></span></span><span> </span><span class="hs-operator">.</span><span> </span><span class="annot"><a href="GHC.Exception.Type.html#Exception"><span class="hs-identifier hs-type">Exception</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531394"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679531394"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531395"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531395"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-196"></span><span id="catchAny"><span class="annot"><span class="annottext">catchAny :: forall a. IO a -&gt; (forall e. Exception e =&gt; e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.html#catchAny"><span class="hs-identifier hs-var hs-var">catchAny</span></a></span></span><span> </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span id="local-6989586621679531291"><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679531291"><span class="hs-identifier hs-var">io</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679531290"><span class="annot"><span class="annottext">forall e. Exception e =&gt; e -&gt; IO a
</span><a href="#local-6989586621679531290"><span class="hs-identifier hs-var">handler</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a)
-&gt; (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, a #))
-&gt; (SomeException -&gt; State# RealWorld -&gt; (# State# RealWorld, a #))
-&gt; State# RealWorld
-&gt; (# State# RealWorld, a #)
forall a b.
(State# RealWorld -&gt; (# State# RealWorld, a #))
-&gt; (b -&gt; State# RealWorld -&gt; (# State# RealWorld, a #))
-&gt; State# RealWorld
-&gt; (# State# RealWorld, a #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#catch%23"><span class="hs-identifier hs-var">catch#</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679531291"><span class="hs-identifier hs-var">io</span></a></span><span> </span><span class="annot"><span class="annottext">SomeException -&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679531289"><span class="hs-identifier hs-var">handler'</span></a></span><span>
</span><span id="line-197"></span><span>    </span><span class="hs-keyword">where</span><span> </span><span id="local-6989586621679531289"><span class="annot"><span class="annottext">handler' :: SomeException -&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679531289"><span class="hs-identifier hs-var hs-var">handler'</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Exception.Type.html#SomeException"><span class="hs-identifier hs-type">SomeException</span></a></span><span> </span><span id="local-6989586621679531285"><span class="annot"><span class="annottext">e
</span><a href="#local-6989586621679531285"><span class="hs-identifier hs-var">e</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO a -&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
forall a. IO a -&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="GHC.Base.html#unIO"><span class="hs-identifier hs-var">unIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">e -&gt; IO a
forall e. Exception e =&gt; e -&gt; IO a
</span><a href="#local-6989586621679531290"><span class="hs-identifier hs-var">handler</span></a></span><span> </span><span class="annot"><span class="annottext">e
</span><a href="#local-6989586621679531285"><span class="hs-identifier hs-var">e</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-198"></span><span>
</span><span id="line-199"></span><span class="hs-comment">-- Using catchException here means that if `m` throws an</span><span>
</span><span id="line-200"></span><span class="hs-comment">-- 'IOError' /as an imprecise exception/, we will not catch</span><span>
</span><span id="line-201"></span><span class="hs-comment">-- it. No one should really be doing that anyway.</span><span>
</span><span id="line-202"></span><span id="local-6989586621679531391"><span class="annot"><a href="GHC.IO.html#mplusIO"><span class="hs-identifier hs-type">mplusIO</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531391"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531391"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531391"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-203"></span><span id="mplusIO"><span class="annot"><span class="annottext">mplusIO :: forall a. IO a -&gt; IO a -&gt; IO a
</span><a href="GHC.IO.html#mplusIO"><span class="hs-identifier hs-var hs-var">mplusIO</span></a></span></span><span> </span><span id="local-6989586621679531283"><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679531283"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span id="local-6989586621679531282"><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679531282"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679531283"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">IO a -&gt; (IOError -&gt; IO a) -&gt; IO a
forall e a. Exception e =&gt; IO a -&gt; (e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.html#catchException"><span class="hs-operator hs-var">`catchException`</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IOError
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Exception.html#IOError"><span class="hs-identifier hs-type">IOError</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679531282"><span class="hs-identifier hs-var">n</span></a></span><span>
</span><span id="line-204"></span><span>
</span><span id="line-205"></span><span class="hs-comment">-- | A variant of 'throw' that can only be used within the 'IO' monad.</span><span>
</span><span id="line-206"></span><span class="hs-comment">--</span><span>
</span><span id="line-207"></span><span class="hs-comment">-- Although 'throwIO' has a type that is an instance of the type of 'throw', the</span><span>
</span><span id="line-208"></span><span class="hs-comment">-- two functions are subtly different:</span><span>
</span><span id="line-209"></span><span class="hs-comment">--</span><span>
</span><span id="line-210"></span><span class="hs-comment">-- &gt; throw e   `seq` x  ===&gt; throw e</span><span>
</span><span id="line-211"></span><span class="hs-comment">-- &gt; throwIO e `seq` x  ===&gt; x</span><span>
</span><span id="line-212"></span><span class="hs-comment">--</span><span>
</span><span id="line-213"></span><span class="hs-comment">-- The first example will cause the exception @e@ to be raised,</span><span>
</span><span id="line-214"></span><span class="hs-comment">-- whereas the second one won\'t.  In fact, 'throwIO' will only cause</span><span>
</span><span id="line-215"></span><span class="hs-comment">-- an exception to be raised when it is used within the 'IO' monad.</span><span>
</span><span id="line-216"></span><span class="hs-comment">-- The 'throwIO' variant should be used in preference to 'throw' to</span><span>
</span><span id="line-217"></span><span class="hs-comment">-- raise an exception within the 'IO' monad because it guarantees</span><span>
</span><span id="line-218"></span><span class="hs-comment">-- ordering with respect to other 'IO' operations, whereas 'throw'</span><span>
</span><span id="line-219"></span><span class="hs-comment">-- does not.</span><span>
</span><span id="line-220"></span><span id="local-6989586621679531388"><span id="local-6989586621679531389"><span class="annot"><a href="GHC.IO.html#throwIO"><span class="hs-identifier hs-type">throwIO</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Exception.Type.html#Exception"><span class="hs-identifier hs-type">Exception</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531389"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679531389"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531388"><span class="hs-identifier hs-type">a</span></a></span></span></span><span>
</span><span id="line-221"></span><span id="throwIO"><span class="annot"><span class="annottext">throwIO :: forall e a. Exception e =&gt; e -&gt; IO a
</span><a href="GHC.IO.html#throwIO"><span class="hs-identifier hs-var hs-var">throwIO</span></a></span></span><span> </span><span id="local-6989586621679531279"><span class="annot"><span class="annottext">e
</span><a href="#local-6989586621679531279"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SomeException -&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
forall a b. a -&gt; State# RealWorld -&gt; (# State# RealWorld, b #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#raiseIO%23"><span class="hs-identifier hs-var">raiseIO#</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">e -&gt; SomeException
forall e. Exception e =&gt; e -&gt; SomeException
</span><a href="GHC.Exception.Type.html#toException"><span class="hs-identifier hs-var">toException</span></a></span><span> </span><span class="annot"><span class="annottext">e
</span><a href="#local-6989586621679531279"><span class="hs-identifier hs-var">e</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-222"></span><span>
</span><span id="line-223"></span><span class="hs-comment">-- -----------------------------------------------------------------------------</span><span>
</span><span id="line-224"></span><span class="hs-comment">-- Controlling asynchronous exception delivery</span><span>
</span><span id="line-225"></span><span>
</span><span id="line-226"></span><span class="hs-comment">-- Applying 'block' to a computation will</span><span>
</span><span id="line-227"></span><span class="hs-comment">-- execute that computation with asynchronous exceptions</span><span>
</span><span id="line-228"></span><span class="hs-comment">-- /blocked/.  That is, any thread which</span><span>
</span><span id="line-229"></span><span class="hs-comment">-- attempts to raise an exception in the current thread with 'Control.Exception.throwTo' will be</span><span>
</span><span id="line-230"></span><span class="hs-comment">-- blocked until asynchronous exceptions are unblocked again.  There\'s</span><span>
</span><span id="line-231"></span><span class="hs-comment">-- no need to worry about re-enabling asynchronous exceptions; that is</span><span>
</span><span id="line-232"></span><span class="hs-comment">-- done automatically on exiting the scope of</span><span>
</span><span id="line-233"></span><span class="hs-comment">-- 'block'.</span><span>
</span><span id="line-234"></span><span class="hs-comment">--</span><span>
</span><span id="line-235"></span><span class="hs-comment">-- Threads created by 'Control.Concurrent.forkIO' inherit the blocked</span><span>
</span><span id="line-236"></span><span class="hs-comment">-- state from the parent; that is, to start a thread in blocked mode,</span><span>
</span><span id="line-237"></span><span class="hs-comment">-- use @block $ forkIO ...@.  This is particularly useful if you need to</span><span>
</span><span id="line-238"></span><span class="hs-comment">-- establish an exception handler in the forked thread before any</span><span>
</span><span id="line-239"></span><span class="hs-comment">-- asynchronous exceptions are received.</span><span>
</span><span id="line-240"></span><span id="local-6989586621679531385"><span class="annot"><a href="GHC.IO.html#block"><span class="hs-identifier hs-type">block</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531385"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531385"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-241"></span><span id="block"><span class="annot"><span class="annottext">block :: forall a. IO a -&gt; IO a
</span><a href="GHC.IO.html#block"><span class="hs-identifier hs-var hs-var">block</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span id="local-6989586621679531276"><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679531276"><span class="hs-identifier hs-var">io</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a)
-&gt; (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, a #))
-&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
forall a.
(State# RealWorld -&gt; (# State# RealWorld, a #))
-&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#maskAsyncExceptions%23"><span class="hs-identifier hs-var">maskAsyncExceptions#</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679531276"><span class="hs-identifier hs-var">io</span></a></span><span>
</span><span id="line-242"></span><span>
</span><span id="line-243"></span><span class="hs-comment">-- To re-enable asynchronous exceptions inside the scope of</span><span>
</span><span id="line-244"></span><span class="hs-comment">-- 'block', 'unblock' can be</span><span>
</span><span id="line-245"></span><span class="hs-comment">-- used.  It scopes in exactly the same way, so on exit from</span><span>
</span><span id="line-246"></span><span class="hs-comment">-- 'unblock' asynchronous exception delivery will</span><span>
</span><span id="line-247"></span><span class="hs-comment">-- be disabled again.</span><span>
</span><span id="line-248"></span><span id="local-6989586621679531275"><span class="annot"><a href="GHC.IO.html#unblock"><span class="hs-identifier hs-type">unblock</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531275"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531275"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-249"></span><span id="unblock"><span class="annot"><span class="annottext">unblock :: forall a. IO a -&gt; IO a
</span><a href="GHC.IO.html#unblock"><span class="hs-identifier hs-var hs-var">unblock</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO a -&gt; IO a
forall a. IO a -&gt; IO a
</span><a href="GHC.IO.html#unsafeUnmask"><span class="hs-identifier hs-var">unsafeUnmask</span></a></span><span>
</span><span id="line-250"></span><span>
</span><span id="line-251"></span><span id="local-6989586621679531273"><span class="annot"><a href="GHC.IO.html#unsafeUnmask"><span class="hs-identifier hs-type">unsafeUnmask</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531273"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531273"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-252"></span><span id="unsafeUnmask"><span class="annot"><span class="annottext">unsafeUnmask :: forall a. IO a -&gt; IO a
</span><a href="GHC.IO.html#unsafeUnmask"><span class="hs-identifier hs-var hs-var">unsafeUnmask</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span id="local-6989586621679531272"><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679531272"><span class="hs-identifier hs-var">io</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a)
-&gt; (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, a #))
-&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
forall a.
(State# RealWorld -&gt; (# State# RealWorld, a #))
-&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#unmaskAsyncExceptions%23"><span class="hs-identifier hs-var">unmaskAsyncExceptions#</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679531272"><span class="hs-identifier hs-var">io</span></a></span><span>
</span><span id="line-253"></span><span>
</span><span id="line-254"></span><span class="hs-comment">-- | Allow asynchronous exceptions to be raised even inside 'mask', making</span><span>
</span><span id="line-255"></span><span class="hs-comment">-- the operation interruptible (see the discussion of &quot;Interruptible operations&quot;</span><span>
</span><span id="line-256"></span><span class="hs-comment">-- in 'Control.Exception').</span><span>
</span><span id="line-257"></span><span class="hs-comment">--</span><span>
</span><span id="line-258"></span><span class="hs-comment">-- When called outside 'mask', or inside 'uninterruptibleMask', this</span><span>
</span><span id="line-259"></span><span class="hs-comment">-- function has no effect.</span><span>
</span><span id="line-260"></span><span class="hs-comment">--</span><span>
</span><span id="line-261"></span><span class="hs-comment">-- @since 4.9.0.0</span><span>
</span><span id="line-262"></span><span id="local-6989586621679531271"><span class="annot"><a href="GHC.IO.html#interruptible"><span class="hs-identifier hs-type">interruptible</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531271"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531271"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-263"></span><span id="interruptible"><span class="annot"><span class="annottext">interruptible :: forall a. IO a -&gt; IO a
</span><a href="GHC.IO.html#interruptible"><span class="hs-identifier hs-var hs-var">interruptible</span></a></span></span><span> </span><span id="local-6989586621679531268"><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679531268"><span class="hs-identifier hs-var">act</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-264"></span><span>  </span><span id="local-6989586621679531267"><span class="annot"><span class="annottext">MaskingState
</span><a href="#local-6989586621679531267"><span class="hs-identifier hs-var">st</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO MaskingState
</span><a href="GHC.IO.html#getMaskingState"><span class="hs-identifier hs-var">getMaskingState</span></a></span><span>
</span><span id="line-265"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">MaskingState
</span><a href="#local-6989586621679531267"><span class="hs-identifier hs-var">st</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-266"></span><span>    </span><span class="annot"><span class="annottext">MaskingState
</span><a href="GHC.IO.html#Unmasked"><span class="hs-identifier hs-var">Unmasked</span></a></span><span>              </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679531268"><span class="hs-identifier hs-var">act</span></a></span><span>
</span><span id="line-267"></span><span>    </span><span class="annot"><span class="annottext">MaskingState
</span><a href="GHC.IO.html#MaskedInterruptible"><span class="hs-identifier hs-var">MaskedInterruptible</span></a></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IO a -&gt; IO a
forall a. IO a -&gt; IO a
</span><a href="GHC.IO.html#unsafeUnmask"><span class="hs-identifier hs-var">unsafeUnmask</span></a></span><span> </span><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679531268"><span class="hs-identifier hs-var">act</span></a></span><span>
</span><span id="line-268"></span><span>    </span><span class="annot"><span class="annottext">MaskingState
</span><a href="GHC.IO.html#MaskedUninterruptible"><span class="hs-identifier hs-var">MaskedUninterruptible</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679531268"><span class="hs-identifier hs-var">act</span></a></span><span>
</span><span id="line-269"></span><span>
</span><span id="line-270"></span><span id="local-6989586621679531263"><span class="annot"><a href="GHC.IO.html#blockUninterruptible"><span class="hs-identifier hs-type">blockUninterruptible</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531263"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531263"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-271"></span><span id="blockUninterruptible"><span class="annot"><span class="annottext">blockUninterruptible :: forall a. IO a -&gt; IO a
</span><a href="GHC.IO.html#blockUninterruptible"><span class="hs-identifier hs-var hs-var">blockUninterruptible</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span id="local-6989586621679531261"><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679531261"><span class="hs-identifier hs-var">io</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a)
-&gt; (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, a #))
-&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
forall a.
(State# RealWorld -&gt; (# State# RealWorld, a #))
-&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#maskUninterruptible%23"><span class="hs-identifier hs-var">maskUninterruptible#</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, a #)
</span><a href="#local-6989586621679531261"><span class="hs-identifier hs-var">io</span></a></span><span>
</span><span id="line-272"></span><span>
</span><span id="line-273"></span><span class="hs-comment">-- | Describes the behaviour of a thread when an asynchronous</span><span>
</span><span id="line-274"></span><span class="hs-comment">-- exception is received.</span><span>
</span><span id="line-275"></span><span class="hs-keyword">data</span><span> </span><span id="MaskingState"><span class="annot"><a href="GHC.IO.html#MaskingState"><span class="hs-identifier hs-var">MaskingState</span></a></span></span><span>
</span><span id="line-276"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="Unmasked"><span class="annot"><a href="GHC.IO.html#Unmasked"><span class="hs-identifier hs-var">Unmasked</span></a></span></span><span> </span><span class="hs-comment">-- ^ asynchronous exceptions are unmasked (the normal state)</span><span>
</span><span id="line-277"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="MaskedInterruptible"><span class="annot"><a href="GHC.IO.html#MaskedInterruptible"><span class="hs-identifier hs-var">MaskedInterruptible</span></a></span></span><span>
</span><span id="line-278"></span><span>      </span><span class="hs-comment">-- ^ the state during 'mask': asynchronous exceptions are masked, but blocking operations may still be interrupted</span><span>
</span><span id="line-279"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span id="MaskedUninterruptible"><span class="annot"><a href="GHC.IO.html#MaskedUninterruptible"><span class="hs-identifier hs-var">MaskedUninterruptible</span></a></span></span><span>
</span><span id="line-280"></span><span>      </span><span class="hs-comment">-- ^ the state during 'uninterruptibleMask': asynchronous exceptions are masked, and blocking operations may not be interrupted</span><span>
</span><span id="line-281"></span><span> </span><span class="hs-keyword">deriving</span><span> </span><span class="hs-special">(</span><span> </span><span id="local-6989586621679531257"><span id="local-6989586621679531259"><span class="annot"><span class="annottext">MaskingState -&gt; MaskingState -&gt; Bool
(MaskingState -&gt; MaskingState -&gt; Bool)
-&gt; (MaskingState -&gt; MaskingState -&gt; Bool) -&gt; Eq MaskingState
forall a. (a -&gt; a -&gt; Bool) -&gt; (a -&gt; a -&gt; Bool) -&gt; Eq a
/= :: MaskingState -&gt; MaskingState -&gt; Bool
$c/= :: MaskingState -&gt; MaskingState -&gt; Bool
== :: MaskingState -&gt; MaskingState -&gt; Bool
$c== :: MaskingState -&gt; MaskingState -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#Eq"><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var">Eq</span></a></span></span></span><span>   </span><span class="hs-comment">-- ^ @since 4.3.0.0</span><span>
</span><span id="line-282"></span><span>          </span><span class="hs-special">,</span><span> </span><span id="local-6989586621679531250"><span id="local-6989586621679531252"><span id="local-6989586621679531254"><span class="annot"><span class="annottext">Int -&gt; MaskingState -&gt; ShowS
[MaskingState] -&gt; ShowS
MaskingState -&gt; String
(Int -&gt; MaskingState -&gt; ShowS)
-&gt; (MaskingState -&gt; String)
-&gt; ([MaskingState] -&gt; ShowS)
-&gt; Show MaskingState
forall a.
(Int -&gt; a -&gt; ShowS) -&gt; (a -&gt; String) -&gt; ([a] -&gt; ShowS) -&gt; Show a
showList :: [MaskingState] -&gt; ShowS
$cshowList :: [MaskingState] -&gt; ShowS
show :: MaskingState -&gt; String
$cshow :: MaskingState -&gt; String
showsPrec :: Int -&gt; MaskingState -&gt; ShowS
$cshowsPrec :: Int -&gt; MaskingState -&gt; ShowS
</span><a href="GHC.Show.html#Show"><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">Show</span></a></span></span></span></span><span> </span><span class="hs-comment">-- ^ @since 4.3.0.0</span><span>
</span><span id="line-283"></span><span>          </span><span class="hs-special">)</span><span>
</span><span id="line-284"></span><span>
</span><span id="line-285"></span><span class="hs-comment">-- | Returns the 'MaskingState' for the current thread.</span><span>
</span><span id="line-286"></span><span class="annot"><a href="GHC.IO.html#getMaskingState"><span class="hs-identifier hs-type">getMaskingState</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.IO.html#MaskingState"><span class="hs-identifier hs-type">MaskingState</span></a></span><span>
</span><span id="line-287"></span><span id="getMaskingState"><span class="annot"><span class="annottext">getMaskingState :: IO MaskingState
</span><a href="GHC.IO.html#getMaskingState"><span class="hs-identifier hs-var hs-var">getMaskingState</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, MaskingState #))
-&gt; IO MaskingState
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, MaskingState #))
 -&gt; IO MaskingState)
-&gt; (State# RealWorld -&gt; (# State# RealWorld, MaskingState #))
-&gt; IO MaskingState
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679531248"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679531248"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-288"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">State# RealWorld -&gt; (# State# RealWorld, Int# #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#getMaskingState%23"><span class="hs-identifier hs-var">getMaskingState#</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679531248"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-289"></span><span>     </span><span class="hs-special">(#</span><span> </span><span id="local-6989586621679531247"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679531247"><span class="hs-identifier hs-var">s'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679531246"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679531246"><span class="hs-identifier hs-var">i</span></a></span></span><span> </span><span class="hs-special">#)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679531247"><span class="hs-identifier hs-var">s'</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679531246"><span class="hs-identifier hs-var">i</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-290"></span><span>                             </span><span class="annot"><span class="annottext">Int#
</span><span class="hs-number">0#</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">MaskingState
</span><a href="GHC.IO.html#Unmasked"><span class="hs-identifier hs-var">Unmasked</span></a></span><span>
</span><span id="line-291"></span><span>                             </span><span class="annot"><span class="annottext">Int#
</span><span class="hs-number">1#</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">MaskingState
</span><a href="GHC.IO.html#MaskedUninterruptible"><span class="hs-identifier hs-var">MaskedUninterruptible</span></a></span><span>
</span><span id="line-292"></span><span>                             </span><span class="annot"><span class="annottext">Int#
</span><span class="hs-identifier">_</span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">MaskingState
</span><a href="GHC.IO.html#MaskedInterruptible"><span class="hs-identifier hs-var">MaskedInterruptible</span></a></span><span> </span><span class="hs-special">#)</span><span>
</span><span id="line-293"></span><span>
</span><span id="line-294"></span><span id="local-6989586621679531375"><span id="local-6989586621679531376"><span class="annot"><a href="GHC.IO.html#onException"><span class="hs-identifier hs-type">onException</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531376"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531375"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531376"><span class="hs-identifier hs-type">a</span></a></span></span></span><span>
</span><span id="line-295"></span><span id="onException"><span class="annot"><span class="annottext">onException :: forall a b. IO a -&gt; IO b -&gt; IO a
</span><a href="GHC.IO.html#onException"><span class="hs-identifier hs-var hs-var">onException</span></a></span></span><span> </span><span id="local-6989586621679531241"><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679531241"><span class="hs-identifier hs-var">io</span></a></span></span><span> </span><span id="local-6989586621679531240"><span class="annot"><span class="annottext">IO b
</span><a href="#local-6989586621679531240"><span class="hs-identifier hs-var">what</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679531241"><span class="hs-identifier hs-var">io</span></a></span><span> </span><span class="annot"><span class="annottext">IO a -&gt; (SomeException -&gt; IO a) -&gt; IO a
forall e a. Exception e =&gt; IO a -&gt; (e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.html#catchException"><span class="hs-operator hs-var">`catchException`</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679531239"><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679531239"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">b
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO b
</span><a href="#local-6989586621679531240"><span class="hs-identifier hs-var">what</span></a></span><span>
</span><span id="line-296"></span><span>                                                   </span><span class="annot"><span class="annottext">SomeException -&gt; IO a
forall e a. Exception e =&gt; e -&gt; IO a
</span><a href="GHC.IO.html#throwIO"><span class="hs-identifier hs-var">throwIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679531239"><span class="hs-identifier hs-var">e</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Exception.Type.html#SomeException"><span class="hs-identifier hs-type">SomeException</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-297"></span><span>
</span><span id="line-298"></span><span class="hs-comment">-- | Executes an IO computation with asynchronous</span><span>
</span><span id="line-299"></span><span class="hs-comment">-- exceptions /masked/.  That is, any thread which attempts to raise</span><span>
</span><span id="line-300"></span><span class="hs-comment">-- an exception in the current thread with 'Control.Exception.throwTo'</span><span>
</span><span id="line-301"></span><span class="hs-comment">-- will be blocked until asynchronous exceptions are unmasked again.</span><span>
</span><span id="line-302"></span><span class="hs-comment">--</span><span>
</span><span id="line-303"></span><span class="hs-comment">-- The argument passed to 'mask' is a function that takes as its</span><span>
</span><span id="line-304"></span><span class="hs-comment">-- argument another function, which can be used to restore the</span><span>
</span><span id="line-305"></span><span class="hs-comment">-- prevailing masking state within the context of the masked</span><span>
</span><span id="line-306"></span><span class="hs-comment">-- computation.  For example, a common way to use 'mask' is to protect</span><span>
</span><span id="line-307"></span><span class="hs-comment">-- the acquisition of a resource:</span><span>
</span><span id="line-308"></span><span class="hs-comment">--</span><span>
</span><span id="line-309"></span><span class="hs-comment">-- &gt; mask $ \restore -&gt; do</span><span>
</span><span id="line-310"></span><span class="hs-comment">-- &gt;     x &lt;- acquire</span><span>
</span><span id="line-311"></span><span class="hs-comment">-- &gt;     restore (do_something_with x) `onException` release</span><span>
</span><span id="line-312"></span><span class="hs-comment">-- &gt;     release</span><span>
</span><span id="line-313"></span><span class="hs-comment">--</span><span>
</span><span id="line-314"></span><span class="hs-comment">-- This code guarantees that @acquire@ is paired with @release@, by masking</span><span>
</span><span id="line-315"></span><span class="hs-comment">-- asynchronous exceptions for the critical parts. (Rather than write</span><span>
</span><span id="line-316"></span><span class="hs-comment">-- this code yourself, it would be better to use</span><span>
</span><span id="line-317"></span><span class="hs-comment">-- 'Control.Exception.bracket' which abstracts the general pattern).</span><span>
</span><span id="line-318"></span><span class="hs-comment">--</span><span>
</span><span id="line-319"></span><span class="hs-comment">-- Note that the @restore@ action passed to the argument to 'mask'</span><span>
</span><span id="line-320"></span><span class="hs-comment">-- does not necessarily unmask asynchronous exceptions, it just</span><span>
</span><span id="line-321"></span><span class="hs-comment">-- restores the masking state to that of the enclosing context.  Thus</span><span>
</span><span id="line-322"></span><span class="hs-comment">-- if asynchronous exceptions are already masked, 'mask' cannot be used</span><span>
</span><span id="line-323"></span><span class="hs-comment">-- to unmask exceptions again.  This is so that if you call a library function</span><span>
</span><span id="line-324"></span><span class="hs-comment">-- with exceptions masked, you can be sure that the library call will not be</span><span>
</span><span id="line-325"></span><span class="hs-comment">-- able to unmask exceptions again.  If you are writing library code and need</span><span>
</span><span id="line-326"></span><span class="hs-comment">-- to use asynchronous exceptions, the only way is to create a new thread;</span><span>
</span><span id="line-327"></span><span class="hs-comment">-- see 'Control.Concurrent.forkIOWithUnmask'.</span><span>
</span><span id="line-328"></span><span class="hs-comment">--</span><span>
</span><span id="line-329"></span><span class="hs-comment">-- Asynchronous exceptions may still be received while in the masked</span><span>
</span><span id="line-330"></span><span class="hs-comment">-- state if the masked thread /blocks/ in certain ways; see</span><span>
</span><span id="line-331"></span><span class="hs-comment">-- &quot;Control.Exception#interruptible&quot;.</span><span>
</span><span id="line-332"></span><span class="hs-comment">--</span><span>
</span><span id="line-333"></span><span class="hs-comment">-- Threads created by 'Control.Concurrent.forkIO' inherit the</span><span>
</span><span id="line-334"></span><span class="hs-comment">-- 'MaskingState' from the parent; that is, to start a thread in the</span><span>
</span><span id="line-335"></span><span class="hs-comment">-- 'MaskedInterruptible' state,</span><span>
</span><span id="line-336"></span><span class="hs-comment">-- use @mask_ $ forkIO ...@.  This is particularly useful if you need</span><span>
</span><span id="line-337"></span><span class="hs-comment">-- to establish an exception handler in the forked thread before any</span><span>
</span><span id="line-338"></span><span class="hs-comment">-- asynchronous exceptions are received.  To create a new thread in</span><span>
</span><span id="line-339"></span><span class="hs-comment">-- an unmasked state use 'Control.Concurrent.forkIOWithUnmask'.</span><span>
</span><span id="line-340"></span><span class="hs-comment">--</span><span>
</span><span id="line-341"></span><span id="local-6989586621679531371"><span class="annot"><a href="GHC.IO.html#mask"><span class="hs-identifier hs-type">mask</span></a></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679531238"><span class="annot"><a href="#local-6989586621679531238"><span class="hs-identifier hs-type">a</span></a></span></span><span class="hs-operator">.</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531238"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531238"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531371"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531371"><span class="hs-identifier hs-type">b</span></a></span></span><span>
</span><span id="line-342"></span><span>
</span><span id="line-343"></span><span class="hs-comment">-- | Like 'mask', but does not pass a @restore@ action to the argument.</span><span>
</span><span id="line-344"></span><span id="local-6989586621679531237"><span class="annot"><a href="GHC.IO.html#mask_"><span class="hs-identifier hs-type">mask_</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531237"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531237"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-345"></span><span>
</span><span id="line-346"></span><span class="hs-comment">-- | Like 'mask', but the masked computation is not interruptible (see</span><span>
</span><span id="line-347"></span><span class="hs-comment">-- &quot;Control.Exception#interruptible&quot;).  THIS SHOULD BE USED WITH</span><span>
</span><span id="line-348"></span><span class="hs-comment">-- GREAT CARE, because if a thread executing in 'uninterruptibleMask'</span><span>
</span><span id="line-349"></span><span class="hs-comment">-- blocks for any reason, then the thread (and possibly the program,</span><span>
</span><span id="line-350"></span><span class="hs-comment">-- if this is the main thread) will be unresponsive and unkillable.</span><span>
</span><span id="line-351"></span><span class="hs-comment">-- This function should only be necessary if you need to mask</span><span>
</span><span id="line-352"></span><span class="hs-comment">-- exceptions around an interruptible operation, and you can guarantee</span><span>
</span><span id="line-353"></span><span class="hs-comment">-- that the interruptible operation will only block for a short period</span><span>
</span><span id="line-354"></span><span class="hs-comment">-- of time.</span><span>
</span><span id="line-355"></span><span class="hs-comment">--</span><span>
</span><span id="line-356"></span><span id="local-6989586621679531236"><span class="annot"><a href="GHC.IO.html#uninterruptibleMask"><span class="hs-identifier hs-type">uninterruptibleMask</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679531235"><span class="annot"><a href="#local-6989586621679531235"><span class="hs-identifier hs-type">a</span></a></span></span><span class="hs-operator">.</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531235"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531235"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531236"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531236"><span class="hs-identifier hs-type">b</span></a></span></span><span>
</span><span id="line-357"></span><span>
</span><span id="line-358"></span><span class="hs-comment">-- | Like 'uninterruptibleMask', but does not pass a @restore@ action</span><span>
</span><span id="line-359"></span><span class="hs-comment">-- to the argument.</span><span>
</span><span id="line-360"></span><span id="local-6989586621679531234"><span class="annot"><a href="GHC.IO.html#uninterruptibleMask_"><span class="hs-identifier hs-type">uninterruptibleMask_</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531234"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531234"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-361"></span><span>
</span><span id="line-362"></span><span id="mask_"><span class="annot"><span class="annottext">mask_ :: forall a. IO a -&gt; IO a
</span><a href="GHC.IO.html#mask_"><span class="hs-identifier hs-var hs-var">mask_</span></a></span></span><span> </span><span id="local-6989586621679531233"><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679531233"><span class="hs-identifier hs-var">io</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">((forall a. IO a -&gt; IO a) -&gt; IO a) -&gt; IO a
forall b. ((forall a. IO a -&gt; IO a) -&gt; IO b) -&gt; IO b
</span><a href="GHC.IO.html#mask"><span class="hs-identifier hs-var">mask</span></a></span><span> </span><span class="annot"><span class="annottext">(((forall a. IO a -&gt; IO a) -&gt; IO a) -&gt; IO a)
-&gt; ((forall a. IO a -&gt; IO a) -&gt; IO a) -&gt; IO a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span class="annot"><span class="annottext">forall a. IO a -&gt; IO a
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679531233"><span class="hs-identifier hs-var">io</span></a></span><span>
</span><span id="line-363"></span><span>
</span><span id="line-364"></span><span id="mask"><span class="annot"><span class="annottext">mask :: forall b. ((forall a. IO a -&gt; IO a) -&gt; IO b) -&gt; IO b
</span><a href="GHC.IO.html#mask"><span class="hs-identifier hs-var hs-var">mask</span></a></span></span><span> </span><span id="local-6989586621679531231"><span class="annot"><span class="annottext">(forall a. IO a -&gt; IO a) -&gt; IO b
</span><a href="#local-6989586621679531231"><span class="hs-identifier hs-var">io</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-365"></span><span>  </span><span id="local-6989586621679531230"><span class="annot"><span class="annottext">MaskingState
</span><a href="#local-6989586621679531230"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO MaskingState
</span><a href="GHC.IO.html#getMaskingState"><span class="hs-identifier hs-var">getMaskingState</span></a></span><span>
</span><span id="line-366"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">MaskingState
</span><a href="#local-6989586621679531230"><span class="hs-identifier hs-var">b</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-367"></span><span>    </span><span class="annot"><span class="annottext">MaskingState
</span><a href="GHC.IO.html#Unmasked"><span class="hs-identifier hs-var">Unmasked</span></a></span><span>              </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IO b -&gt; IO b
forall a. IO a -&gt; IO a
</span><a href="GHC.IO.html#block"><span class="hs-identifier hs-var">block</span></a></span><span> </span><span class="annot"><span class="annottext">(IO b -&gt; IO b) -&gt; IO b -&gt; IO b
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">(forall a. IO a -&gt; IO a) -&gt; IO b
</span><a href="#local-6989586621679531231"><span class="hs-identifier hs-var">io</span></a></span><span> </span><span class="annot"><span class="annottext">forall a. IO a -&gt; IO a
</span><a href="GHC.IO.html#unblock"><span class="hs-identifier hs-var">unblock</span></a></span><span>
</span><span id="line-368"></span><span>    </span><span class="annot"><span class="annottext">MaskingState
</span><a href="GHC.IO.html#MaskedInterruptible"><span class="hs-identifier hs-var">MaskedInterruptible</span></a></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(forall a. IO a -&gt; IO a) -&gt; IO b
</span><a href="#local-6989586621679531231"><span class="hs-identifier hs-var">io</span></a></span><span> </span><span class="annot"><span class="annottext">forall a. IO a -&gt; IO a
</span><a href="GHC.IO.html#block"><span class="hs-identifier hs-var">block</span></a></span><span>
</span><span id="line-369"></span><span>    </span><span class="annot"><span class="annottext">MaskingState
</span><a href="GHC.IO.html#MaskedUninterruptible"><span class="hs-identifier hs-var">MaskedUninterruptible</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(forall a. IO a -&gt; IO a) -&gt; IO b
</span><a href="#local-6989586621679531231"><span class="hs-identifier hs-var">io</span></a></span><span> </span><span class="annot"><span class="annottext">forall a. IO a -&gt; IO a
</span><a href="GHC.IO.html#blockUninterruptible"><span class="hs-identifier hs-var">blockUninterruptible</span></a></span><span>
</span><span id="line-370"></span><span>
</span><span id="line-371"></span><span id="uninterruptibleMask_"><span class="annot"><span class="annottext">uninterruptibleMask_ :: forall a. IO a -&gt; IO a
</span><a href="GHC.IO.html#uninterruptibleMask_"><span class="hs-identifier hs-var hs-var">uninterruptibleMask_</span></a></span></span><span> </span><span id="local-6989586621679531229"><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679531229"><span class="hs-identifier hs-var">io</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">((forall a. IO a -&gt; IO a) -&gt; IO a) -&gt; IO a
forall b. ((forall a. IO a -&gt; IO a) -&gt; IO b) -&gt; IO b
</span><a href="GHC.IO.html#uninterruptibleMask"><span class="hs-identifier hs-var">uninterruptibleMask</span></a></span><span> </span><span class="annot"><span class="annottext">(((forall a. IO a -&gt; IO a) -&gt; IO a) -&gt; IO a)
-&gt; ((forall a. IO a -&gt; IO a) -&gt; IO a) -&gt; IO a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span class="annot"><span class="annottext">forall a. IO a -&gt; IO a
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679531229"><span class="hs-identifier hs-var">io</span></a></span><span>
</span><span id="line-372"></span><span>
</span><span id="line-373"></span><span id="uninterruptibleMask"><span class="annot"><span class="annottext">uninterruptibleMask :: forall b. ((forall a. IO a -&gt; IO a) -&gt; IO b) -&gt; IO b
</span><a href="GHC.IO.html#uninterruptibleMask"><span class="hs-identifier hs-var hs-var">uninterruptibleMask</span></a></span></span><span> </span><span id="local-6989586621679531227"><span class="annot"><span class="annottext">(forall a. IO a -&gt; IO a) -&gt; IO b
</span><a href="#local-6989586621679531227"><span class="hs-identifier hs-var">io</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-374"></span><span>  </span><span id="local-6989586621679531226"><span class="annot"><span class="annottext">MaskingState
</span><a href="#local-6989586621679531226"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO MaskingState
</span><a href="GHC.IO.html#getMaskingState"><span class="hs-identifier hs-var">getMaskingState</span></a></span><span>
</span><span id="line-375"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">MaskingState
</span><a href="#local-6989586621679531226"><span class="hs-identifier hs-var">b</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-376"></span><span>    </span><span class="annot"><span class="annottext">MaskingState
</span><a href="GHC.IO.html#Unmasked"><span class="hs-identifier hs-var">Unmasked</span></a></span><span>              </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IO b -&gt; IO b
forall a. IO a -&gt; IO a
</span><a href="GHC.IO.html#blockUninterruptible"><span class="hs-identifier hs-var">blockUninterruptible</span></a></span><span> </span><span class="annot"><span class="annottext">(IO b -&gt; IO b) -&gt; IO b -&gt; IO b
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">(forall a. IO a -&gt; IO a) -&gt; IO b
</span><a href="#local-6989586621679531227"><span class="hs-identifier hs-var">io</span></a></span><span> </span><span class="annot"><span class="annottext">forall a. IO a -&gt; IO a
</span><a href="GHC.IO.html#unblock"><span class="hs-identifier hs-var">unblock</span></a></span><span>
</span><span id="line-377"></span><span>    </span><span class="annot"><span class="annottext">MaskingState
</span><a href="GHC.IO.html#MaskedInterruptible"><span class="hs-identifier hs-var">MaskedInterruptible</span></a></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IO b -&gt; IO b
forall a. IO a -&gt; IO a
</span><a href="GHC.IO.html#blockUninterruptible"><span class="hs-identifier hs-var">blockUninterruptible</span></a></span><span> </span><span class="annot"><span class="annottext">(IO b -&gt; IO b) -&gt; IO b -&gt; IO b
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">(forall a. IO a -&gt; IO a) -&gt; IO b
</span><a href="#local-6989586621679531227"><span class="hs-identifier hs-var">io</span></a></span><span> </span><span class="annot"><span class="annottext">forall a. IO a -&gt; IO a
</span><a href="GHC.IO.html#block"><span class="hs-identifier hs-var">block</span></a></span><span>
</span><span id="line-378"></span><span>    </span><span class="annot"><span class="annottext">MaskingState
</span><a href="GHC.IO.html#MaskedUninterruptible"><span class="hs-identifier hs-var">MaskedUninterruptible</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(forall a. IO a -&gt; IO a) -&gt; IO b
</span><a href="#local-6989586621679531227"><span class="hs-identifier hs-var">io</span></a></span><span> </span><span class="annot"><span class="annottext">forall a. IO a -&gt; IO a
</span><a href="GHC.IO.html#blockUninterruptible"><span class="hs-identifier hs-var">blockUninterruptible</span></a></span><span>
</span><span id="line-379"></span><span>
</span><span id="line-380"></span><span id="local-6989586621679531365"><span id="local-6989586621679531366"><span id="local-6989586621679531367"><span class="annot"><a href="GHC.IO.html#bracket"><span class="hs-identifier hs-type">bracket</span></a></span><span>
</span><span id="line-381"></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531367"><span class="hs-identifier hs-type">a</span></a></span><span>         </span><span class="hs-comment">-- ^ computation to run first (\&quot;acquire resource\&quot;)</span><span>
</span><span id="line-382"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679531367"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531366"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span>  </span><span class="hs-comment">-- ^ computation to run last (\&quot;release resource\&quot;)</span><span>
</span><span id="line-383"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679531367"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531365"><span class="hs-identifier hs-type">c</span></a></span><span class="hs-special">)</span><span>  </span><span class="hs-comment">-- ^ computation to run in-between</span><span>
</span><span id="line-384"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531365"><span class="hs-identifier hs-type">c</span></a></span></span></span></span><span>         </span><span class="hs-comment">-- returns the value from the in-between computation</span><span>
</span><span id="line-385"></span><span id="bracket"><span class="annot"><span class="annottext">bracket :: forall a b c. IO a -&gt; (a -&gt; IO b) -&gt; (a -&gt; IO c) -&gt; IO c
</span><a href="GHC.IO.html#bracket"><span class="hs-identifier hs-var hs-var">bracket</span></a></span></span><span> </span><span id="local-6989586621679531221"><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679531221"><span class="hs-identifier hs-var">before</span></a></span></span><span> </span><span id="local-6989586621679531220"><span class="annot"><span class="annottext">a -&gt; IO b
</span><a href="#local-6989586621679531220"><span class="hs-identifier hs-var">after</span></a></span></span><span> </span><span id="local-6989586621679531219"><span class="annot"><span class="annottext">a -&gt; IO c
</span><a href="#local-6989586621679531219"><span class="hs-identifier hs-var">thing</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-386"></span><span>  </span><span class="annot"><span class="annottext">((forall a. IO a -&gt; IO a) -&gt; IO c) -&gt; IO c
forall b. ((forall a. IO a -&gt; IO a) -&gt; IO b) -&gt; IO b
</span><a href="GHC.IO.html#mask"><span class="hs-identifier hs-var">mask</span></a></span><span> </span><span class="annot"><span class="annottext">(((forall a. IO a -&gt; IO a) -&gt; IO c) -&gt; IO c)
-&gt; ((forall a. IO a -&gt; IO a) -&gt; IO c) -&gt; IO c
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679531218"><span class="annot"><span class="annottext">forall a. IO a -&gt; IO a
</span><a href="#local-6989586621679531218"><span class="hs-identifier hs-var">restore</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-387"></span><span>    </span><span id="local-6989586621679531217"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679531217"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679531221"><span class="hs-identifier hs-var">before</span></a></span><span>
</span><span id="line-388"></span><span>    </span><span id="local-6989586621679531216"><span class="annot"><span class="annottext">c
</span><a href="#local-6989586621679531216"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO c -&gt; IO c
forall a. IO a -&gt; IO a
</span><a href="#local-6989586621679531218"><span class="hs-identifier hs-var">restore</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; IO c
</span><a href="#local-6989586621679531219"><span class="hs-identifier hs-var">thing</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679531217"><span class="hs-identifier hs-var">a</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">IO c -&gt; IO b -&gt; IO c
forall a b. IO a -&gt; IO b -&gt; IO a
</span><a href="GHC.IO.html#onException"><span class="hs-operator hs-var">`onException`</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; IO b
</span><a href="#local-6989586621679531220"><span class="hs-identifier hs-var">after</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679531217"><span class="hs-identifier hs-var">a</span></a></span><span>
</span><span id="line-389"></span><span>    </span><span class="annot"><span class="annottext">b
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">a -&gt; IO b
</span><a href="#local-6989586621679531220"><span class="hs-identifier hs-var">after</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679531217"><span class="hs-identifier hs-var">a</span></a></span><span>
</span><span id="line-390"></span><span>    </span><span class="annot"><span class="annottext">c -&gt; IO c
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">c
</span><a href="#local-6989586621679531216"><span class="hs-identifier hs-var">r</span></a></span><span>
</span><span id="line-391"></span><span>
</span><span id="line-392"></span><span id="local-6989586621679531214"><span id="local-6989586621679531215"><span class="annot"><a href="GHC.IO.html#finally"><span class="hs-identifier hs-type">finally</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531215"><span class="hs-identifier hs-type">a</span></a></span><span>         </span><span class="hs-comment">-- ^ computation to run first</span><span>
</span><span id="line-393"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531214"><span class="hs-identifier hs-type">b</span></a></span><span>         </span><span class="hs-comment">-- ^ computation to run afterward (even if an exception</span><span>
</span><span id="line-394"></span><span>                        </span><span class="hs-comment">-- was raised)</span><span>
</span><span id="line-395"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531215"><span class="hs-identifier hs-type">a</span></a></span></span></span><span>         </span><span class="hs-comment">-- returns the value from the first computation</span><span>
</span><span id="line-396"></span><span id="local-6989586621679531210"><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679531210"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span id="finally"><span class="annot"><span class="annottext">finally :: forall a b. IO a -&gt; IO b -&gt; IO a
</span><a href="GHC.IO.html#finally"><span class="hs-operator hs-var hs-var">`finally`</span></a></span></span><span> </span><span id="local-6989586621679531209"><span class="annot"><span class="annottext">IO b
</span><a href="#local-6989586621679531209"><span class="hs-identifier hs-var">sequel</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-397"></span><span>  </span><span class="annot"><span class="annottext">((forall a. IO a -&gt; IO a) -&gt; IO a) -&gt; IO a
forall b. ((forall a. IO a -&gt; IO a) -&gt; IO b) -&gt; IO b
</span><a href="GHC.IO.html#mask"><span class="hs-identifier hs-var">mask</span></a></span><span> </span><span class="annot"><span class="annottext">(((forall a. IO a -&gt; IO a) -&gt; IO a) -&gt; IO a)
-&gt; ((forall a. IO a -&gt; IO a) -&gt; IO a) -&gt; IO a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679531208"><span class="annot"><span class="annottext">forall a. IO a -&gt; IO a
</span><a href="#local-6989586621679531208"><span class="hs-identifier hs-var">restore</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-398"></span><span>    </span><span id="local-6989586621679531207"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679531207"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO a -&gt; IO a
forall a. IO a -&gt; IO a
</span><a href="#local-6989586621679531208"><span class="hs-identifier hs-var">restore</span></a></span><span> </span><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621679531210"><span class="hs-identifier hs-var">a</span></a></span><span> </span><span class="annot"><span class="annottext">IO a -&gt; IO b -&gt; IO a
forall a b. IO a -&gt; IO b -&gt; IO a
</span><a href="GHC.IO.html#onException"><span class="hs-operator hs-var">`onException`</span></a></span><span> </span><span class="annot"><span class="annottext">IO b
</span><a href="#local-6989586621679531209"><span class="hs-identifier hs-var">sequel</span></a></span><span>
</span><span id="line-399"></span><span>    </span><span class="annot"><span class="annottext">b
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO b
</span><a href="#local-6989586621679531209"><span class="hs-identifier hs-var">sequel</span></a></span><span>
</span><span id="line-400"></span><span>    </span><span class="annot"><span class="annottext">a -&gt; IO a
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679531207"><span class="hs-identifier hs-var">r</span></a></span><span>
</span><span id="line-401"></span><span>
</span><span id="line-402"></span><span class="hs-comment">-- | Evaluate the argument to weak head normal form.</span><span>
</span><span id="line-403"></span><span class="hs-comment">--</span><span>
</span><span id="line-404"></span><span class="hs-comment">-- 'evaluate' is typically used to uncover any exceptions that a lazy value</span><span>
</span><span id="line-405"></span><span class="hs-comment">-- may contain, and possibly handle them.</span><span>
</span><span id="line-406"></span><span class="hs-comment">--</span><span>
</span><span id="line-407"></span><span class="hs-comment">-- 'evaluate' only evaluates to /weak head normal form/. If deeper</span><span>
</span><span id="line-408"></span><span class="hs-comment">-- evaluation is needed, the @force@ function from @Control.DeepSeq@</span><span>
</span><span id="line-409"></span><span class="hs-comment">-- may be handy:</span><span>
</span><span id="line-410"></span><span class="hs-comment">--</span><span>
</span><span id="line-411"></span><span class="hs-comment">-- &gt; evaluate $ force x</span><span>
</span><span id="line-412"></span><span class="hs-comment">--</span><span>
</span><span id="line-413"></span><span class="hs-comment">-- There is a subtle difference between @'evaluate' x@ and @'return' '$!' x@,</span><span>
</span><span id="line-414"></span><span class="hs-comment">-- analogous to the difference between 'throwIO' and 'throw'. If the lazy</span><span>
</span><span id="line-415"></span><span class="hs-comment">-- value @x@ throws an exception, @'return' '$!' x@ will fail to return an</span><span>
</span><span id="line-416"></span><span class="hs-comment">-- 'IO' action and will throw an exception instead. @'evaluate' x@, on the</span><span>
</span><span id="line-417"></span><span class="hs-comment">-- other hand, always produces an 'IO' action; that action will throw an</span><span>
</span><span id="line-418"></span><span class="hs-comment">-- exception upon /execution/ iff @x@ throws an exception upon /evaluation/.</span><span>
</span><span id="line-419"></span><span class="hs-comment">--</span><span>
</span><span id="line-420"></span><span class="hs-comment">-- The practical implication of this difference is that due to the</span><span>
</span><span id="line-421"></span><span class="hs-comment">-- /imprecise exceptions/ semantics,</span><span>
</span><span id="line-422"></span><span class="hs-comment">--</span><span>
</span><span id="line-423"></span><span class="hs-comment">-- &gt; (return $! error &quot;foo&quot;) &gt;&gt; error &quot;bar&quot;</span><span>
</span><span id="line-424"></span><span class="hs-comment">--</span><span>
</span><span id="line-425"></span><span class="hs-comment">-- may throw either @&quot;foo&quot;@ or @&quot;bar&quot;@, depending on the optimizations</span><span>
</span><span id="line-426"></span><span class="hs-comment">-- performed by the compiler. On the other hand,</span><span>
</span><span id="line-427"></span><span class="hs-comment">--</span><span>
</span><span id="line-428"></span><span class="hs-comment">-- &gt; evaluate (error &quot;foo&quot;) &gt;&gt; error &quot;bar&quot;</span><span>
</span><span id="line-429"></span><span class="hs-comment">--</span><span>
</span><span id="line-430"></span><span class="hs-comment">-- is guaranteed to throw @&quot;foo&quot;@.</span><span>
</span><span id="line-431"></span><span class="hs-comment">--</span><span>
</span><span id="line-432"></span><span class="hs-comment">-- The rule of thumb is to use 'evaluate' to force or handle exceptions in</span><span>
</span><span id="line-433"></span><span class="hs-comment">-- lazy values. If, on the other hand, you are forcing a lazy value for</span><span>
</span><span id="line-434"></span><span class="hs-comment">-- efficiency reasons only and do not care about exceptions, you may</span><span>
</span><span id="line-435"></span><span class="hs-comment">-- use @'return' '$!' x@.</span><span>
</span><span id="line-436"></span><span id="local-6989586621679531357"><span class="annot"><a href="GHC.IO.html#evaluate"><span class="hs-identifier hs-type">evaluate</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679531357"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679531357"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-437"></span><span id="evaluate"><span class="annot"><span class="annottext">evaluate :: forall a. a -&gt; IO a
</span><a href="GHC.IO.html#evaluate"><span class="hs-identifier hs-var hs-var">evaluate</span></a></span></span><span> </span><span id="local-6989586621679531206"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679531206"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a)
-&gt; (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679531205"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679531205"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">a -&gt; State# RealWorld -&gt; (# State# RealWorld, a #)
forall a d. a -&gt; State# d -&gt; (# State# d, a #)
</span><a href="../../ghc-prim/src/GHC.Prim.html#seq%23"><span class="hs-identifier hs-var">seq#</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679531206"><span class="hs-identifier hs-var">a</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679531205"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-comment">-- NB. see #2273, #5129</span><span>
</span><span id="line-438"></span><span>
</span><span id="line-439"></span><span class="hs-comment">{- $exceptions_and_strictness

Laziness can interact with @catch@-like operations in non-obvious ways (see,
e.g. GHC #11555 and #13330). For instance, consider these subtly-different
examples:

&gt; test1 = Control.Exception.catch (error &quot;uh oh&quot;) (\(_ :: SomeException) -&gt; putStrLn &quot;it failed&quot;)
&gt;
&gt; test2 = GHC.IO.catchException (error &quot;uh oh&quot;) (\(_ :: SomeException) -&gt; putStrLn &quot;it failed&quot;)

While @test1@ will print &quot;it failed&quot;, @test2@ will print &quot;uh oh&quot;.

When using 'catchException', exceptions thrown while evaluating the
action-to-be-executed will not be caught; only exceptions thrown during
execution of the action will be handled by the exception handler.

Since this strictness is a small optimization and may lead to surprising
results, all of the @catch@ and @handle@ variants offered by &quot;Control.Exception&quot;
use 'catch' rather than 'catchException'.
-}</span><span>
</span><span id="line-459"></span><span>
</span><span id="line-460"></span><span class="hs-comment">-- For SOURCE import by GHC.Base to define failIO.</span><span>
</span><span id="line-461"></span><span class="annot"><a href="GHC.IO.html#mkUserError"><span class="hs-identifier hs-type">mkUserError</span></a></span><span>       </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span class="hs-special">]</span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Exception.Type.html#SomeException"><span class="hs-identifier hs-type">SomeException</span></a></span><span>
</span><span id="line-462"></span><span id="mkUserError"><span class="annot"><span class="annottext">mkUserError :: String -&gt; SomeException
</span><a href="GHC.IO.html#mkUserError"><span class="hs-identifier hs-var hs-var">mkUserError</span></a></span></span><span> </span><span id="local-6989586621679531204"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679531204"><span class="hs-identifier hs-var">str</span></a></span></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IOError -&gt; SomeException
forall e. Exception e =&gt; e -&gt; SomeException
</span><a href="GHC.Exception.Type.html#toException"><span class="hs-identifier hs-var">toException</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; IOError
</span><a href="GHC.IO.Exception.html#userError"><span class="hs-identifier hs-var">userError</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679531204"><span class="hs-identifier hs-var">str</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-463"></span></pre></body></html>